package com.h3c.ptability.mapstruct;

import com.h3c.ptability.dto.electronicSign.PtEsignDocTemplateDTO;
import com.h3c.ptability.entity.PtEsignDocTemplate;
import com.h3c.ptability.vo.PtEsignDocTemplateVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author chenyifan
 * @date 2022/5/24 11:35
 */
@Mapper
public interface PtEsignDocTemplateMapstruct {

    PtEsignDocTemplateMapstruct INSTANCE = Mappers.getMapper(PtEsignDocTemplateMapstruct.class);

    /**
     * dto转换成实体类
     * @param templateDTO
     * @return
     */
    PtEsignDocTemplate DTO2Entity(PtEsignDocTemplateDTO templateDTO);

    /**
     * 实体类转dto
     * @param templateDTO dto
     * @return
     */
    PtEsignDocTemplateDTO entityToDto(PtEsignDocTemplate templateDTO);

    List<PtEsignDocTemplateDTO> entityToDto(List<PtEsignDocTemplate> templateDTO);

    /**
     * 将实体类列表转换成vo列表
     * @param docTemplates
     * @return
     */
    List<PtEsignDocTemplateVO> entityList2VoList(List<PtEsignDocTemplate> docTemplates);

    /**
     * 填充属性
     * @param voList
     */
    @AfterMapping
    default void afterEntityList2VoList(@MappingTarget List<PtEsignDocTemplateVO> voList){
        voList.stream().forEach(s->{
            s.setVariablesCount(s.getDocVariables().size());
        });
    }
}
